home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / wot-20080519-fx.xpi / chrome / wot.jar / content / api / submit.js < prev    next >
Text File  |  2008-02-21  |  2KB  |  99 lines

  1. /*
  2.     api/submit.js
  3.  
  4.     Copyright ┬⌐ 2005, 2006, 2007  Against Intuition, Inc. <info@mywot.com>
  5. */
  6.  
  7. var wot_api_submit =
  8. {
  9.     init: function()
  10.     {
  11.     },
  12.  
  13.     send: function(prefname, target, testimonies)
  14.     {
  15.         try {
  16.             if (!wot_api_register.ready) {
  17.                 return;
  18.             }
  19.  
  20.             if (!prefname || prefname.charAt(0) != '.' || !target ||
  21.                     !testimonies) {
  22.                 return;
  23.             }
  24.  
  25.             var hostname = wot_url.gethostname(target);
  26.  
  27.             if (!hostname) {
  28.                 return;
  29.             }
  30.  
  31.             var nonce = wot_crypto.nonce();
  32.             var context =
  33.                 wot_arc4.create(wot_hash.hmac_sha1hex(wot_prefs.witness_key,
  34.                     nonce));
  35.  
  36.             if (!context) {
  37.                 return;
  38.             }
  39.  
  40.             var crypted_target =
  41.                 wot_arc4.crypt(context, wot_hash.strtobin(hostname));
  42.  
  43.             if (!crypted_target) {
  44.                 return;
  45.             }
  46.  
  47.             var query_string = WOT_SERVICE_API_SUBMIT +
  48.                 "?id="        + wot_prefs.witness_id +
  49.                 "&nonce="    + nonce +
  50.                 "&target="    + encodeURIComponent(btoa(
  51.                                 wot_hash.bintostr(crypted_target)));
  52.  
  53.             var found = 0;
  54.  
  55.             for (var i = 0; i < WOT_APPLICATIONS; ++i) {
  56.                 if (testimonies[i] >= 0) {
  57.                     query_string += "&testimony_" + i + "=" + testimonies[i];
  58.                     ++found;
  59.                 }
  60.             }
  61.  
  62.             query_string += "&lang=" + wot_util.getstring("language") +
  63.                             "&version=" + WOT_PLATFORM + "-" + WOT_VERSION;
  64.  
  65.             if (!found) {
  66.                 return;
  67.             }
  68.  
  69.             var request = new XMLHttpRequest();
  70.  
  71.             request.open("GET", WOT_SERVICE_NORMAL +
  72.                 wot_crypto.authenticate_query(query_string));
  73.  
  74.             new wot_cookie_remover(request);
  75.  
  76.             request.onload = function(event)
  77.             {
  78.                 try {
  79.                     if (request.status == 200) {
  80.                         var submit = request.responseXML.getElementsByTagName(
  81.                                         WOT_SERVICE_XML_SUBMIT);
  82.                         if (submit) {
  83.                             wot_pending.clear(prefname);
  84.                         }
  85.                     }
  86.                 } catch (e) {
  87.                     dump("wot_api_submit.onload: failed with " + e + "\n");
  88.                 }
  89.             };
  90.  
  91.             request.send(null);
  92.         } catch (e) {
  93.             dump("wot_api_submit.send: failed with " + e + "\n");
  94.         }
  95.     }
  96. };
  97.  
  98. wot_api_submit.init();
  99.